package com.wangyadong.hobby.jmh;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.AverageTime)
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class LogEfficiencyTest {
    private final Logger logger = LoggerFactory.getLogger(getClass());


    @Benchmark
    public void testAppendStringLog() {
        for (int i = 0; i < 1000; i++) {
            logger.info("{} {} {} {}", "=====-4-9-090-90-90-90-90-90-asdasdasdasd90-as9d0-as9d0-as", i+"", i + "", i + "", i + "");
        }
    }

    @Benchmark
    public void testStringLog() {
        for (int i = 0; i < 1000; i++) {
            logger.info("=====-4-9-090-90-90-90-90-90-asdasdasdasd90-as9d0-as9d0-as " + i + "" + i + "" + i + "" + i);
        }
    }

    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder().include(LogEfficiencyTest.class.getSimpleName())
                .forks(1)
                .warmupIterations(10)
                .measurementIterations(10)
                .build();
        new Runner(options).run();
    }
}
